package fi.hut.soberit.agilefant.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

import fi.hut.soberit.agilefant.business.AgilefantWidgetBusiness;
import fi.hut.soberit.agilefant.model.AgilefantWidget;

@Component("widgetAction")
@Scope("prototype")
public class WidgetAction extends ActionSupport implements CRUDAction {

    private static final long serialVersionUID = 2143301123898713933L;
    
    private AgilefantWidget widget;
    
    private Integer widgetId;
    private Integer collectionId;
    private Integer objectId;
    
    private String type;
    private Integer position;
    private Integer listNumber;

    @Autowired
    private AgilefantWidgetBusiness agilefantWidgetBusiness;
    
    public String create() {
        widget = agilefantWidgetBusiness.create(type, objectId, collectionId);
        return Action.SUCCESS;
    }

    public String delete() {
        agilefantWidgetBusiness.delete(widgetId);
        return Action.SUCCESS;
    }

    public String retrieve() {
        // TODO Auto-generated method stub
        return null;
    }

    public String store() {
        // TODO Auto-generated method stub
        return null;
    }
    
    public String move() {
        widget = agilefantWidgetBusiness.retrieve(widgetId);
        agilefantWidgetBusiness.move(widget, position, listNumber);
        return Action.SUCCESS;
    }
    
    /*
     * AUTOGENERATED LIST OF SETTERS AND GETTERS
     */

    public AgilefantWidget getWidget() {
        return widget;
    }

    public void setWidget(AgilefantWidget widget) {
        this.widget = widget;
    }

    public Integer getWidgetId() {
        return widgetId;
    }

    public void setWidgetId(Integer widgetId) {
        this.widgetId = widgetId;
    }

    public Integer getCollectionId() {
        return collectionId;
    }

    public void setCollectionId(Integer collectionId) {
        this.collectionId = collectionId;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Integer getPosition() {
        return position;
    }

    public void setPosition(Integer position) {
        this.position = position;
    }

    public Integer getListNumber() {
        return listNumber;
    }

    public void setListNumber(Integer listNumber) {
        this.listNumber = listNumber;
    }

    public Integer getObjectId() {
        return objectId;
    }

    public void setObjectId(Integer objectId) {
        this.objectId = objectId;
    }

}
